package com.qch.concurrent.demo_03_cyclicBarrier;


import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @Author qch
 * @Date 2021/8/2
 * 协调多个线程一起执行某个操作
 */
public class Main {
    public static void main(String[] args) throws InterruptedException, BrokenBarrierException {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(5, new Runnable() {
            public void run() {
                System.out.println(Thread.currentThread().getName()+"该阶段结束");
            }
        });
        //如果只有4，main线程会一直阻塞
        for (int i = 0; i < 5; i++) {
            new MyThread("线程"+(i+1),cyclicBarrier).start();
        }

    }
}
